﻿using System.Collections.Generic;
using System.Data;
using System.Text;

namespace lhservice.common
{
  public static class ExtendDataTable
  {
    public static List<Dictionary<string,dynamic>> ToList(this DataTable _orgObj)
    {
      var res = new List<Dictionary<string, dynamic>>();
      if (_orgObj == null) return res;

      foreach (DataRow row in _orgObj.Rows)
      {
        var _data = new Dictionary<string, dynamic>();
        foreach (DataColumn col in _orgObj.Columns)
        {
          _data[Encoding.GetEncoding("gbk").GetString(Encoding.GetEncoding("ibm850").GetBytes(col.ColumnName.ToString() ?? ""))] = row[col.ColumnName];
        }
        res.Add(_data);
      }

      return res;
    }
  }
}
